﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LoongCAD.Geometry.Friendly;
using LoongCAD.STC.Friendly.Plugins;
using LoongCAD.STC.Friendly.Scene;
using LoongCAD.STC.Friendly.Scene.UI;

namespace HelloComponents {
    /// <summary>
    /// 自定义组件示例(无主次零件，自定义输入的组件对象）
    /// 组件项目需作为一个独立目录放置于{模型目录}/config/comps下
    /// 主程序DLL必须命名为plugin.dll, 单个plugin.dll可同时包含多个组件
    /// TestModel/config/comps/HelloComponents/thumbnail_1001.png: 组件缩略图，128x128, 用于组件管理器中图标模式下显示
    /// TestModel/config/comps/HelloComponents/icon_1001.png: 组件工具栏图标(正常状态), 24x24
    /// TestModel/config/comps/HelloComponents/icon_1001_revs.png: 组件工具栏图标(选中状态), 24x24
    /// </summary>
    [Plugin("HelloCustom")] //组件名称
    [PluginAuthor("LoongCAD")] //作者
    [PluginNumber(1001)] //组件编号
    [PluginUserInterface("HelloCustomForm")] //组件UI界面
    [PluginGroup("LoongSTC Examples")] //组件分组
    [PluginThumbnailLocation("thumbnail_1001", "")] //组件缩略图文件名称
    [PluginIconLocation("icon_1001", "")] //组件工具栏图标文件名称
    public class HelloCustom : LoongCAD.STC.Friendly.Plugins.CustomPlugin
    {
        /// <summary>
        /// 输入参数数据集合
        /// </summary>
        private HelloCustomData m_data = null;

        /// <summary>
        /// 构造函数
        /// </summary>
        /// <param name="data">本次组件运行的输入参数</param>
        public HelloCustom(HelloCustomData data) {
            m_data = data;
        }

        /// <summary>
        /// 定义组件用户输入
        /// </summary>
        /// <returns>用户输入列表</returns>
        public override List<InputDefinition> DefineInput() {
            try {
                var picker = new Picker();
                var pt0 = picker.PickPoint("选择第一点");
                var pt1 = picker.PickPoint("选择第二点", pt0);
                return new List<InputDefinition> {
                    new InputDefinition(pt0),
                    new InputDefinition(pt1)
                };
            }
            catch {
                return new List<InputDefinition>();
            }
        }

        /// <summary>
        /// 运行组件
        /// </summary>
        /// <param name="comp">组件实例对象</param>
        /// <param name="input">输入参数列表</param>
        /// <returns>本次组件运行是否成功</returns>
        public override bool Run(Component comp, List<InputDefinition> input) {
            //检查用户输入是否合法
            if (input.Count != 2)
                return false;

            //根据用户点选的两个点，创建一根梁
            var beam = new Beam();
            beam.StartPoint = (Point)input[0].GetInput();
            beam.EndPoint = (Point)input[1].GetInput();
            beam.Profile.ProfileString = m_data.Profile;
            beam.Material.MaterialString = m_data.Material;
            beam.Class = m_data.Class.ToString();
            beam.Insert();
            return true;
        }


    }
}
